package com.application.library.util;

import java.text.DecimalFormat;

public class MathUtil {

    /**
     *
     * @param diameterBig 大图的直径
     * @param diameterSmall 小图的直径
     * @return 小图的中心位于大图圆形边界，小图需要移动的距离
     */
    public static int margePx(int diameterBig, int diameterSmall) {
        double radiusBig = diameterBig / 2;
        double radiusSmall = diameterSmall / 2;
        double inradiumBig = Math.sqrt(radiusBig * radiusBig * 2);
        double inradiumSmall = Math.sqrt(radiusSmall * radiusSmall * 2);
        double shortOf1 = inradiumBig - inradiumSmall;
        double shortOf2 = diameterBig / 2;
        double shortOf = shortOf1 - shortOf2;
        boolean add = shortOf > 0;
        double returnDouble = Math.sqrt(shortOf * shortOf / 2);
        return (int) (returnDouble * (add ? 1 : -1));
    }

    /**
     * 格式化数字,默认格式为0.00
     *
     * @param number
     * @return System.out.println(newDecimalFormat(",###").format(c));　　　//299,792,458
     */
    public static String format(double number) {
        if (number == 0) {
            return format(number, "0.00");
        }
        return format(number, "0.00");
    }

    /**
     * 格式化数字
     *
     * @param number    需要格式化的数字
     * @param formatStr 字符串格式 如：0.00
     * @return
     */
    public static String format(double number, String formatStr) {
        DecimalFormat df = new DecimalFormat(formatStr);
        return df.format(number);
    }

}
